<?php

if (!defined('NV_ADMIN')) {
    die ("Access Denied");
}

$aid = trim($aid);
$sql = "select radminsuper from ".$prefix."_authors where aid='$aid'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$radminsuper = $row[radminsuper];
if ($radminsuper==1) {

/*********************************************************/
/* REVIEWS Block Functions				 */
/*********************************************************/

function modules() {
    global $adminfile, $prefix, $db, $multilingual, $bgcolor2, $Home_Module;
    include ("../header.php");
    GraphicAdmin();
    OpenTable();
    echo "<center><font class=\"title\"><b>"._MODULESADMIN."</b></font></center>";
    CloseTable();
    OpenTable();
    echo "<br><center><font class=\"option\">"._MODULESADDONS."</font><br><br>"
	."<font class=\"content\">"._MODULESACTIVATION."</font><br><br>"
	.""._MODULEHOMENOTE." <a href=$adminfile.php?op=Configure>"._MODULEHOMENOTE2."</a>!<br><br>"//M09 / 26.7.2006
	."<form action=\"".$adminfile.".php\" method=\"post\">"
	."<table border=\"1\" align=\"center\" width=\"90%\"><tr><td align=\"center\" bgcolor=\"$bgcolor2\">"
	."<b>"._TITLE."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._CUSTOMTITLE."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._STATUS."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._VIEW."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._FUNCTIONS."</b></td></tr>";

    $sql = "select mid, title, custom_title, active, view, inmenu from ".$prefix."_modules order by title ASC";
    $result = $db->sql_query($sql);
    while($row = $db->sql_fetchrow($result)) {
	$mid = $row[mid];
	$title = $row[title];
	$custom_title = $row[custom_title];
	$active = $row[active];
	$view = $row[view];
	$inmenu = $row[inmenu];
	$mid = intval($mid);
	if ($custom_title == "") {
	    $custom_title = ereg_replace("_"," ",$title);
	    $db->sql_query("update ".$prefix."_modules set custom_title='$custom_title' where mid='$mid'");
	}
	if ($active == 1) {
	    $active = _ACTIVE;
	    $change = _DEACTIVATE;
	    $act = 0;
	} else {
	    $active = "<i>"._INACTIVE."</i>";
	    $change = _ACTIVATE;
	    $act = 1;
	}
	if ($custom_title == "") {
	    $custom_title = ereg_replace("_", " ", $title);
	}
	if ($view == 0) {
	    $who_view = _MVALL;
	} elseif ($view == 1) {
	    $who_view = _MVUSERS;
	} elseif ($view == 2) {
	    $who_view = _MVADMIN;
	}
	if ($title != $Home_Module AND $inmenu == 0) {
	    $title = "[ <big><strong>&middot;</strong></big> ] $title";
	}
	if ($title == $Home_Module) {
	    $title = "<b>$title</b>";
	    $custom_title = "<b>$custom_title</b>";
	    $active = "<b>$active ("._INHOME.")</b>";
	    $who_view = "<b>$who_view</b>";
	    $change_status = "<i>$change</i>";
	    $background = "bgcolor=\"$bgcolor2\"";
	} else {
	    $change_status = "<a href=\"".$adminfile.".php?op=module_status&mid=$mid&active=$act\">$change</a>";
	    $background = "";
	}

	echo "<tr><td $background>&nbsp;$title</td><td align=\"center\" $background>$custom_title</td><td align=\"center\" $background>$active</td><td align=\"center\" $background>$who_view</td><td align=\"center\" $background nowrap>[ <a href=\"".$adminfile.".php?op=module_edit&mid=$mid\">"._EDIT."</a> | $change_status ]</td></tr>";
    }
    echo "</table>";
    CloseTable();
    include ("../footer.php");
}


function module_status($mid, $active) {
    global $adminfile, $prefix, $db;
    $mid = intval($mid);
    $db->sql_query("update ".$prefix."_modules set active='$active' where mid='$mid'");
    Header("Location: ".$adminfile.".php?op=modules");
}

function module_edit($mid) {
    global $adminfile, $prefix, $db, $Home_Module;

    $main_module = $Home_Module;
    $mid = intval($mid);
    $sql = "select title, custom_title, view, inmenu from ".$prefix."_modules where mid='$mid'";
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $title = $row[title];
    $custom_title = $row[custom_title];
    $view = $row[view];
    $inmenu = $row[inmenu];

    include ("../header.php");
    GraphicAdmin();
    title(""._MODULEEDIT."");
    OpenTable();
    if ($view == 0) {
	$sel1 = "selected";
	$sel2 = "";
	$sel3 = "";
    } elseif ($view == 1) {
	$sel1 = "";
	$sel2 = "selected";
	$sel3 = "";
    } elseif ($view == 2) {
	$sel1 = "";
	$sel2 = "";
	$sel3 = "selected";    
    }
    if ($title == $main_module) {
	$a = " - "._INHOME."";
    } else {
	$a = "";
    }
    if ($inmenu == 1) {
	$insel1 = "checked";
	$insel2 = "";
    } elseif ($inmenu == 0) {
	$insel1 = "";
	$insel2 = "checked";
    }
    echo "<center><b>"._CHANGEMODNAME."</b><br>($title$a)</center><br><br>"
	."<form action=\"".$adminfile.".php\" method=\"post\">"
	."<table border=\"0\"><tr><td>"
	.""._CUSTOMMODNAME."</td><td>"
	."<input type=\"text\" name=\"custom_title\" value=\"$custom_title\" size=\"50\"></td></tr>";
    if ($title == $main_module) {
	echo "<input type=\"hidden\" name=\"view\" value=\"0\">"
	    ."<input type=\"hidden\" name=\"inmenu\" value=\"$inmenu\">"
	    ."</table><br><br>";
    } else {
	echo "<tr><td>"._VIEWPRIV."</td><td><select name=\"view\">"
	    ."<option value=\"0\" $sel1>"._MVALL."</option>"
	    ."<option value=\"1\" $sel2>"._MVUSERS."</option>"
	    ."<option value=\"2\" $sel3>"._MVADMIN."</option>"
	    ."</select></tr></td>";

	echo "<tr><td>"._SHOWINMENU."</td><td>"
	    ."<input type=\"radio\" name=\"inmenu\" value=\"1\" $insel1> "._YES." &nbsp;&nbsp; <input type=\"radio\" name=\"inmenu\" value=\"0\" $insel2> "._NO.""
	    ."</td></tr></table><br><br>";
    }
    if ($title != $main_module) {
	
    }
    echo "<input type=\"hidden\" name=\"mid\" value=\"$mid\">"
	."<input type=\"hidden\" name=\"op\" value=\"module_edit_save\">"
	."<input type=\"submit\" value=\""._SAVECHANGES."\">"
	."</form>"
	."<br><br><center>"._GOBACK."</center>";
    CloseTable();
    include("../footer.php");
}

function module_edit_save($mid, $custom_title, $view, $inmenu) {
    global $adminfile, $prefix, $db;
    $mid = intval($mid);
    if ($view != 1) { $mod_group = 0; }
    $db->sql_query("update ".$prefix."_modules set custom_title='$custom_title', view='$view', inmenu='$inmenu' where mid='$mid'");
    Header("Location: ".$adminfile.".php?op=modules");
}

switch ($op){

    case "modules":
    modules();
    break;

    case "module_status":
    module_status($mid, $active);
    break;

    case "module_edit":
    module_edit($mid);
    break;
    
    case "module_edit_save":
    module_edit_save($mid, $custom_title, $view, $inmenu);
    break;


}

} else {
    echo "Access Denied";
}

?>
